import { Component, OnInit } from '@angular/core';
import { Router, NavigationExtras } from '@angular/router';
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { AuthTokenService } from '@services/auth-token.service';
@Component({
  selector: 'app-bank-account',
  templateUrl: './bank-account.page.html',
  styleUrls: ['./bank-account.page.scss'],
})
export class BankAccountPage implements OnInit {

  bankAccounts = [];
  constructor(
    public http: HttpClient,
    private authTokenService: AuthTokenService,
    private router:Router
  ) {
    this.initPage();
   }

   appuserid = this.authTokenService.getAppUserId()
   initPage(){
     let url = '/scm/app/getBankAccountList.do';  
     let request = {
      "appuserid":this.appuserid
     };
    this.http.post(url,request).subscribe(
      (response:any)=>{
        console.info(response);
        this.bankAccounts = response.responseBody.banks;
        if(this.bankAccounts.length == 0){
          let navigationExtras: NavigationExtras = {
            queryParams:{
              errType:0,
              errorContent:'The BANK ACCOUNT page data is empty',
              title:'BANK ACCOUNT',
              backUrl:'/tabs/myAccount'
            }
          };
          this.router.navigate(['/common-error'],navigationExtras);
        }
      });
   }
  ngOnInit() {
  }

  dataEmpty :boolean = true;

  toAccountDetail(item){
    let navigationExtras: NavigationExtras = {
      queryParams:item
    };
    this.router.navigate(['/tabs/myAccount/bank-account/account-detail'],navigationExtras);
  }
}
